/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef CHANLISTEDITOR_H
#define CHANLISTEDITOR_H

#include <QObject>
#include <QDialog>
#include <QDomDocument>
#include <QTreeWidgetItem>
#include <QVariant>
#include <QMap>

#include "chanagents/agentfactory.h"

#include "ui_chanlisteditor.h"

namespace Wishmaster
{
	class ChanAgent;
}

class PropertyHub
{
public:
	PropertyHub();
	virtual ~PropertyHub();

	void setProperty(const QString& key, const QVariant& value);
	QVariant property(const QString& key);
	QStringList allKeys();

private:
	QVariantMap m_values;
};

class ChanListItem : public QTreeWidgetItem, public PropertyHub
{
public:
	ChanListItem(const QString& name, QTreeWidget* parent);
	ChanListItem(const QString& name, QTreeWidgetItem* parent);

	static const int ChanItem = UserType + 1;
	static const int BoardItem = UserType + 2;
private:
};

class AgentSettingsItem : public QTreeWidgetItem, public PropertyHub
{
public:
	AgentSettingsItem(const QString& name, QTreeWidgetItem* parent);
	static const int AgentSettings = UserType + 3;

private:
};

class ChanListEditor : public QDialog
{ Q_OBJECT
public:
	ChanListEditor(QWidget* parent = 0);
	virtual ~ChanListEditor();

	bool loadChanlist(const QString& filename);
	bool saveChanlist(const QString& filename);

public slots:
	void accept();
	void reject();
	void clicked(QAbstractButton* button);

protected slots:
	void itemActivated(QTreeWidgetItem* item, int column); 
	void itemSelectionChanged();
	void propertyChanged(QTableWidgetItem* item);
	void addProperty();
	void removeProperty();
	void saveAs();
	void addChan();
	void addBoard();
	void removeChan();
	void updateColumnSizes();

protected:
	ChanListItem* addBoardItem(ChanListItem* parent, const QString& name, const QString& alias);
	void addAgentItem(ChanListItem* parent, const QMap<QString, QString> settings);

private:
	Ui::ChanListEditor* m_ui;
	QString m_filename;
	QList<Wishmaster::ChanAgent*> m_agentList;
	Wishmaster::AgentFactory* m_agentFactory;
};

#endif
